package com.jxc.jxc01.grc.web;

import com.alibaba.fastjson.JSON;
import com.jxc.jxc01.grc.entity.RespResult;
import com.jxc.jxc01.grc.entity.Vendor;
import com.jxc.jxc01.grc.service.IVendorService;
import com.jxc.jxc01.grc.service.impl.VendorServiceImpl;
import com.jxc.jxc01.hch.entity.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import static java.lang.System.out;

@WebServlet(value = "/obscureVendor")
public class ObscureVendorServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=utf-8");
        IVendorService vendorService = new VendorServiceImpl();
        String suppliername = request.getParameter("suppliername");
        System.out.println(suppliername);
        List<Vendor> vendors = vendorService.queryVendorsByFuzzyStr(suppliername);
        System.out.println(vendors);

        if (vendors != null && vendors.size() > 0) {
//            int count = vendorService.queryVendorsTotalCount();
            RespResult result = new RespResult();
            result.setCode(0);
            result.setMessage("ok");
            result.setCount(vendors.size());
            result.setData(vendors);
            HttpSession session = request.getSession();
            session.setAttribute("result",result);
            response.sendRedirect("gongyingshang.html");
        }


    }
}
